<?php require_once LAYOUTPATH.'layout_header.php'; ?>

<h1><?php echo $page_title; ?></h1>

<div id="bricabox_tabs" class="admin">
	<ul>
		<li class="back"><a href="/">&lsaquo; Back to your BricaBox</a></li>
		<?php render_tabs($admin_tabs); ?>
	</ul>
	<ul id="sub_tabs">
		<li><a href="/admin/general/basic">Basic</a></li>
		<li><a href="/admin/general/terms">Interaction</a></li>
		<li><a href="/admin/general/appearance">Appearance</a></li>
		<li class="current"><a href="/admin/general/domain">Domain name</a></li>
	</ul>
</div>

<?php require_once FLASHPARTIAL; ?>

<form action="/bricabox/<?php echo $bricabox->id; ?>/save" method="post" onsubmit="return checkForm();">
	<input type="hidden" name="section" value="general" />
	<input type="hidden" name="view" value="domain" />
	<fieldset>
		<div>
			<input type="hidden" name="bricabox[use_custom_domain]" value="0" />
			<input onclick="toggleDomain();" type="checkbox" id="use_custom_domain" name="bricabox[use_custom_domain]" value="1"<?php if ($bricabox->use_custom_domain) echo ' checked="checked"'; ?> />
			<label for="use_custom_domain">I want to host my BricaBox on a custom domain (e.g. kylebragger.com)</label>
				<a href="#help_domain">Help! How does this work?</a><br />
		</div>
		
		<script type="text/javascript" charset="utf-8">
			function toggleDomain()
			{
				var el = $('#use_custom_domain');
				if (el.attr('checked') == true)
					$('#custom_domain_wrap').show();
				else
					$('#custom_domain_wrap').hide();
			}
		</script>
		
		<div class="opt_group" id="custom_domain_wrap" <?php if (!$bricabox->use_custom_domain): ?>style="display: none;"<?php endif; ?>>
			<div class="inner">
				<div>
					<label for="custom_domain">I'd like to host my BricaBox at</label>
					<input type="text" id="custom_domain" name="bricabox[custom_domain]" value="<?php echo $bricabox->custom_domain; ?>" />
				</div>
				
				<div>
					<label for="api_key_google_maps">My <a href="http://code.google.com/apis/maps/signup.html" target="_blank">Google Maps API key</a> is:</label>
					<input type="text" id="api_key_google_maps" name="bricabox[api_key_google_maps]" value="<?php echo $bricabox->api_key_google_maps; ?>" />
					(This is required if you'd like to use the Google Maps block on your BricaBox.)
				</div>
			</div>
		</div>
		
		<script type="text/javascript" charset="utf-8">
			function checkForm()
			{
				var use = $('#use_custom_domain');
				var cdm = $('#custom_domain');
				var gmk = $('#api_key_google_maps');
				if (use.attr('checked'))
				{
					if (!cdm.val() || !gmk.val())
					{
						alert("Please enter your custom domain and a Google Maps API key.");
						return false;
					}
				}
			}
		</script>
		
		<div class="controls">
			<input type="submit" value="Save changes" />
			or <a href="/admin">cancel</a>
		</div>
	</fieldset>
</form>

<div class="big_info_box" id="help_domain">
	<h4>How do I use my custom domain?</h4>
	<p>If you would like host your BricaBox site at your own domain (i.e. at yourdomain.com instead of yourdomain.bricabox.com), register your domain with your registrar, point its 'CNAME record' at bricabox.com, and enter your credentials above. If you plan on using our Google Maps feature, you must also register for a Google Maps API key on Google's website. For more information about using custom domains, <a href="http://what.bricabox.com/content/797">visit this entry in our knowledgebase</a>.</p>
</div>

<?php require_once LAYOUTPATH.'layout_footer.php'; ?>